package yxy.cherry.battle.module.affix.skill;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.AffixContext.AffixActionClass;
import yxy.cherry.battle.module.affix.AffixContext.AffixTarget;
import yxy.cherry.battle.module.affix.AffixFactory.SkillTypeEnum;
import yxy.cherry.battle.module.affix.Skill;
import yxy.cherry.battle.module.affix.SkillType;
import yxy.cherry.battle.module.record.stream.RecordStream;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_02_攻击伤害;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

import java.util.ArrayList;
import java.util.Collection;

/** 伤害绝对值 */
@SkillType(Type = SkillTypeEnum.伤害绝对值)
public class Affix_13_伤害绝对值 extends Skill {

	private int get伤害值() {
		return getParam(0);
	}

	private int get伤害次数() {
		return getParam(1);
	}

	public Affix_13_伤害绝对值(Fighter actor, skill skilldata, int probability, int[] params) {
		super(actor, skilldata, probability, params);
	}

	private RecordStreamGroup steamGroup;

	@Override
	public RecordStreamGroup record() {
		steamGroup = getRecord().stream(new RecordStreamGroup());
		steamGroup.add(new RecordStream_SKL(getActor(), getSkillId()));
		return steamGroup;
	}

	@Override
	public boolean _exec(Collection<Fighter> targets) {
		// 检查预设目标
		ArrayList<Fighter> targetList = new ArrayList<>();
		if (getAffixAction().get目标们().size() > 0) {
			targetList.addAll(getAffixAction().get目标们Fighter());
		} else {
			targetList.addAll(targets);
			getAffixAction().setTargets(targetList);
		}

		boolean 有效 = false;
		for (Fighter target : targetList) {
			有效 |= exec(getActor(), target);
		}
		return 有效;
	}

	@Override
	public boolean exec(Fighter actor, Fighter target) {
		if (!target.is活着()) {
			return false;
		}
		getAffixAction().set针对目标(target);
		AffixTarget affixTarget = getAffixAction().getTarget(target);

		RecordStream recordSteam = steamGroup.add(new RecordStream_02_攻击伤害(affixTarget));

		long 总伤害 = get伤害值();

		for (int i = 0, size = get伤害次数(); i < size; i++) {
			affixTarget.get伤害流().add(总伤害);
			affixTarget.get效果流().add(0L);
		}
		总伤害 = affixTarget.总伤害();

		target.set伤害(总伤害);

		getAffixAction().add行动类型(AffixActionClass.有伤害);

		// 流脚本
		recordSteam.record();

		if (!target.is活着()) {
			getAffixAction().add死掉的武将(target);
			getAffixAction().add行动类型(AffixActionClass.有击杀);
			target.handle本方有死将();
		}

		// 统计
		getRecord().get统计().getFighter(actor.getFighterPosition()).addDMG(总伤害);
		getRecord().get统计().getFighter(target.getFighterPosition()).addHUT(总伤害);

		Battle.battleLogger(6,"伤害绝对值：施法者："+actor.getName()+"目标："+target.getName()+"造成伤害：" + affixTarget.get伤害流().toString());
		return true;
	}

}